import { getIntl, request } from "@umijs/max";
import qs from 'qs';



//通用规则
export async function createDictType(params: any): Promise<BackendResponse<any>> {
    let url ='/admin-api/system/dict-type/create';
    return request(url, {
        method: 'POST',
        data: params,

    });
}

export async function getDictTypeById(id: string): Promise<BackendResponse<any>> {
    let url =`/admin-api/system/dict-type/get/${id}`;
    return request(url, {
        method: 'GET'
    });
}


export async function updateDictType(id:string,params: any): Promise<BackendResponse<any>> {
    let url =`/admin-api/system/dict-type/update/${id}`;
    return request(url, {
        method: 'PUT',
        data: params,
    });
}

export async function updateDictTypeStatus(id:string,status: any): Promise<BackendResponse<any>> {
    let url =`/admin-api/system/dict-type/update-status/${id}`;
    return request(url, {
        method: 'PUT',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        data: qs.stringify({ status })
    });
}


export async function pageDictType(params: any): Promise<BackendResponse<any>> {
    let url ='/admin-api/system/dict-type/page';
    return request(url, {
        method: 'POST',
        data: params,
    });
}

export async function deleteDictType(id: string): Promise<BackendResponse<any>> {
    let url =`/admin-api/system/dict-type/delete/${id}`;
    return request(url, {
        method: 'DELETE'
    });
}


export async function listDictDatas(type:string): Promise<BackendResponse<any>> {
    let url =`/admin-api/system/dict-data/list/${type}`;
    return request(url, {
        method: 'GET',
        // params: { type }
    });
}

export async function deleteDictData(id: string): Promise<BackendResponse<any>> {
    let url =`/admin-api/system/dict-data/delete`;
    return request(url, {
        method: 'DELETE',
         headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        data: qs.stringify({ id })
    });
}


export async function createDictData(data: any): Promise<BackendResponse<any>> {
    let url =`/admin-api/system/dict-data/create`;
    return request(url, {
        method: 'POST',
        data: data
    });
}


export async function updateDictData(data: any): Promise<BackendResponse<any>> {
    let url =`/admin-api/system/dict-data/update`;
    return request(url, {
        method: 'PUT',
        data: data
    });
}